package com.zzjson.rabbit.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.rabbit.producer</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年04月27日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@Service
@Slf4j
public class MessageProducer {
	@Qualifier("amqpTemplate")
	@Autowired
	private AmqpTemplate rabbitTemplate;
	@Qualifier("amqpTemplate2")
	@Autowired
	private AmqpTemplate amqpTemplate2;

	public void sendMessage(String message) {
		log.info("send message {}", message);
		rabbitTemplate.convertAndSend("FirstKey", message);
		rabbitTemplate.convertAndSend("SecondKey", "[Direct,SecondKey] " + message);

		// Exchange模式为topic，通过topic匹配关心该主题的队列
		amqpTemplate2.convertAndSend("msg.Third.send", "[Topic,msg.Third.send] " + message);

		// 广播消息，与Exchange绑定的所有队列都会收到消息，routingKey为空
		amqpTemplate2.convertAndSend("MY_FANOUT_EXCHANGE", null, "[Fanout] " + message);
	}

}